package soap.utils;

import com.alibaba.fastjson.JSONObject;
import soap.entity.po.User;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

/**
 * Created by ZhangPY on 2020/6/26
 * Belong Organization OVERUN-9299
 * overun9299@163.com
 * Explain:
 */
public class AuthUtils {

    /**
     * 在请求头中获取User
     * @param request
     * @return
     */
    public static User getUserFromRequest(HttpServletRequest request) {

        Enumeration<String> userInfo = request.getHeaders("userInfo");
        return JSONObject.parseObject(userInfo.nextElement(), User.class);
    }


    /**
     * 在请求头中获取token
     * @param request
     * @return
     */
    public static String getTokenFromRequest(HttpServletRequest request) {

        Enumeration<String> token = request.getHeaders("token");
        return token.nextElement();
    }
}
